home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 May / Chip Mayıs 2001.iso / prog / share / 14 / setup.exe / %MAINDIR% / Scripts / Java App / Source / TEConnectionSample.java < prev   
Encoding:
Java Source  |  2001-03-30  |  6.9 KB  |  248 lines

  1. import com.ms.wfc.app.*;
  2. import com.ms.wfc.core.*;
  3. import com.ms.wfc.ui.*;
  4. import com.ms.wfc.html.*;
  5. import com.ms.com.*;
  6.  
  7. import ftpte.*;
  8.  
  9. /**
  10.  * This class can take a variable number of parameters on the command
  11.  * line. Program execution begins with the main() method. The class
  12.  * constructor is not invoked unless an object of type 'TEConnectionSample' is
  13.  * created in the main() method.
  14.  */
  15. public class TEConnectionSample extends Form
  16. {
  17.     //Interface to the ftpte COM object.
  18.     ITEConnection m_TEConnection;
  19.  
  20.     public TEConnectionSample()
  21.     {
  22.         // Required for Visual J++ Form Designer support
  23.         initForm();        
  24.  
  25.         // TODO: Add any constructor code after initForm call
  26.         //Create the TEConnection COM object.
  27.         try
  28.         {
  29.             Status.addItem("Not Connected.");    
  30.             m_TEConnection = new TEConnection ();    
  31.             ftpsite.setEnabled(true);
  32.             Connect.setEnabled(true);
  33.         }
  34.         catch (Exception e)
  35.         {
  36.             Status.addItem("Failed to create the TEConnection object.");    
  37.             System.out.println("Unexpected exception " + e);
  38.             e.printStackTrace();
  39.         }
  40.     }
  41.  
  42.     /**
  43.      * TEConnectionSample overrides dispose so it can clean up the
  44.      * component list.
  45.      */
  46.     public void dispose()
  47.     {
  48.         super.dispose();
  49.         components.dispose();
  50.     }
  51.  
  52.     private void TEConnectionSample_click(Object source, Event e)
  53.     {
  54.         
  55.     }
  56.  
  57.     private void Connect_click(Object source, Event e)
  58.     {
  59.         try
  60.         {
  61.             m_TEConnection.setHost(ftpsite.getText());
  62.             m_TEConnection.setProtocol("FTP");
  63.             m_TEConnection.setLogin("ftp");
  64.             m_TEConnection.setPassword("u@ur.com");
  65.             m_TEConnection.Connect();
  66.             
  67.             RemotePath.setEnabled(true);
  68.             RemoteFolder.setEnabled(true);
  69.             RemoteFolder.focus();
  70.             
  71.             Status.addItem("Connected to : " + ftpsite.getText() + " site.");
  72.             Status.setScrollAlwaysVisible(true);
  73.         }
  74.         catch (Exception exp)
  75.         {
  76.             Status.addItem("Failed to connected to : " + ftpsite.getText() + " site.");
  77.             Status.setScrollAlwaysVisible(true);
  78.         }
  79.     }
  80.  
  81.     private void RemotePath_click(Object source, Event e)
  82.     {
  83.         try
  84.         {
  85.             m_TEConnection.setRemoteFolder(RemoteFolder.getText());
  86.             String strRemoteFolder = m_TEConnection.getRemoteFolder();
  87.             
  88.             download.setEnabled(true);
  89.             filename.setEnabled(true);
  90.             filename.focus();
  91.         
  92.             Status.addItem("Set Remote path to : " + RemoteFolder.getText());            
  93.         }
  94.         catch(Exception exp)
  95.         {
  96.             Status.addItem("Failed to set remote path to : " + RemoteFolder.getText());            
  97.         }
  98.     }
  99.  
  100.     private void download_click(Object source, Event e)
  101.     {
  102.         try
  103.         {
  104.             m_TEConnection.Download(filename.getText(),filename.getText());
  105.             Status.addItem("Downloading the file.");
  106.             Status.addItem("Check the status in CuteFTP pro Transfer Engine");
  107.         }
  108.         catch(Exception exp)
  109.         {
  110.             Status.addItem("Failed to download the file.");    
  111.         }
  112.     }
  113.  
  114.     /**
  115.      * NOTE: The following code is required by the Visual J++ form
  116.      * designer.  It can be modified using the form editor.  Do not
  117.      * modify it using the code editor.
  118.      */
  119.     Container components = new Container();
  120.     RichEdit richEdit1 = new RichEdit();
  121.     Label label2 = new Label();
  122.     Edit ftpsite = new Edit();
  123.     Button Connect = new Button();
  124.     Edit RemoteFolder = new Edit();
  125.     Button RemotePath = new Button();
  126.     Label label4 = new Label();
  127.     Label label1 = new Label();
  128.     Edit filename = new Edit();
  129.     Button download = new Button();
  130.     ListBox Status = new ListBox();
  131.     Label label3 = new Label();
  132.  
  133.     private void initForm()
  134.     {
  135.         this.setText("TEConnectionSample");
  136.         this.setAutoScaleBaseSize(new Point(5, 13));
  137.         this.setClientSize(new Point(343, 240));
  138.         this.addOnClick(new EventHandler(this.TEConnectionSample_click));
  139.  
  140.         richEdit1.setBackColor(Color.INFO);
  141.         richEdit1.setFont(new Font("MS Sans Serif", 9.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
  142.         richEdit1.setForeColor(Color.ACTIVECAPTION);
  143.         richEdit1.setLocation(new Point(16, 16));
  144.         richEdit1.setSize(new Point(312, 24));
  145.         richEdit1.setTabIndex(6);
  146.         richEdit1.setTabStop(false);
  147.         richEdit1.setText("      Java CuteFTP Pro TE Connection Sample.");
  148.  
  149.         label2.setLocation(new Point(16, 48));
  150.         label2.setSize(new Point(100, 16));
  151.         label2.setTabIndex(7);
  152.         label2.setTabStop(false);
  153.         label2.setText("Ftp Site:");
  154.  
  155.         ftpsite.setLocation(new Point(16, 64));
  156.         ftpsite.setSize(new Point(216, 20));
  157.         ftpsite.setTabIndex(0);
  158.         ftpsite.setText("");
  159.  
  160.         Connect.setEnabled(false);
  161.         Connect.setLocation(new Point(240, 64));
  162.         Connect.setSize(new Point(80, 24));
  163.         Connect.setTabIndex(1);
  164.         Connect.setText("Connect");
  165.         Connect.addOnClick(new EventHandler(this.Connect_click));
  166.  
  167.         RemoteFolder.setEnabled(false);
  168.         RemoteFolder.setLocation(new Point(16, 104));
  169.         RemoteFolder.setSize(new Point(216, 20));
  170.         RemoteFolder.setTabIndex(2);
  171.         RemoteFolder.setText("");
  172.  
  173.         RemotePath.setEnabled(false);
  174.         RemotePath.setLocation(new Point(240, 104));
  175.         RemotePath.setSize(new Point(80, 24));
  176.         RemotePath.setTabIndex(3);
  177.         RemotePath.setText("Remote Folder");
  178.         RemotePath.addOnClick(new EventHandler(this.RemotePath_click));
  179.  
  180.         label4.setLocation(new Point(16, 88));
  181.         label4.setSize(new Point(100, 16));
  182.         label4.setTabIndex(8);
  183.         label4.setTabStop(false);
  184.         label4.setText("Remote Folder:");
  185.  
  186.         label1.setLocation(new Point(16, 128));
  187.         label1.setSize(new Point(100, 16));
  188.         label1.setTabIndex(9);
  189.         label1.setTabStop(false);
  190.         label1.setText("File to download:");
  191.  
  192.         filename.setEnabled(false);
  193.         filename.setLocation(new Point(16, 144));
  194.         filename.setSize(new Point(216, 20));
  195.         filename.setTabIndex(4);
  196.         filename.setText("");
  197.  
  198.         download.setEnabled(false);
  199.         download.setLocation(new Point(240, 144));
  200.         download.setSize(new Point(80, 24));
  201.         download.setTabIndex(5);
  202.         download.setText("Download <<");
  203.         download.addOnClick(new EventHandler(this.download_click));
  204.  
  205.         Status.setBackColor(new Color(224, 224, 224));
  206.         Status.setFont(new Font("MS Sans Serif", 8.0f, FontSize.POINTS, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
  207.         Status.setForeColor(Color.HIGHLIGHT);
  208.         Status.setLocation(new Point(16, 192));
  209.         Status.setSize(new Point(304, 30));
  210.         Status.setTabIndex(11);
  211.         Status.setTabStop(false);
  212.         Status.setText("listBox1");
  213.         Status.setSelectionMode(SelectionMode.MULTI_SIMPLE);
  214.         Status.setUseTabStops(true);
  215.  
  216.         label3.setLocation(new Point(16, 176));
  217.         label3.setSize(new Point(100, 16));
  218.         label3.setTabIndex(10);
  219.         label3.setTabStop(false);
  220.         label3.setText("Current Status:");
  221.  
  222.         this.setNewControls(new Control[] {
  223.                             label3, 
  224.                             Status, 
  225.                             download, 
  226.                             filename, 
  227.                             label1, 
  228.                             label4, 
  229.                             RemotePath, 
  230.                             RemoteFolder, 
  231.                             Connect, 
  232.                             ftpsite, 
  233.                             label2, 
  234.                             richEdit1});
  235.     }
  236.  
  237.     /**
  238.      * The main entry point for the application. 
  239.      *
  240.      * @param args Array of parameters passed to the application
  241.      * via the command line.
  242.      */
  243.     public static void main(String args[])
  244.     {
  245.         Application.run(new TEConnectionSample());
  246.     }
  247. }
  248.